package com.zhongzhi.controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.zhongzhi.service.MeasureService;
import com.zhongzhi.springboot.pojo.Aisle;
import com.zhongzhi.springboot.pojo.Bo;
import com.zhongzhi.springboot.pojo.JsonResult;
import com.zhongzhi.springboot.pojo.Measure;
/**
 * 测量业务层
 * @author Administrator
 *
 */
@RestController
@RequestMapping("/measure/")
public class MeasureController {

	@Autowired
	private MeasureService measureService;

	//增加测试数据(业务自动增加)
	@RequestMapping("insert")
	public JsonResult insert(Measure measure) {
		Bo bo = measureService.insert(measure);
		if(bo.isBool()) {
			//插入数据返回id
			return new JsonResult(200,"增加数据成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"增加数据失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//修改测试数据
	@RequestMapping("update")
	public JsonResult update(Measure measure) {
		Bo bo = measureService.insert(measure);
		if(bo.isBool()) {
			return new JsonResult(200,"修改数据成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"修改数据失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}

	//删除业务数据
	@RequestMapping("delete")
	public JsonResult delete(Integer id) {
		Bo bo = measureService.delete(id);
		if(bo.isBool()) {
			return new JsonResult(200,"删除数据成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"删除数据失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//批量删除数据
	@RequestMapping("deletes")
	public JsonResult deletes(Integer... ids) {
		Bo bo = measureService.deletes(ids);
		if(bo.isBool()) {
			return new JsonResult(200,"批量删除数据成功",bo.getSize(),null);
		}else {
			return new JsonResult(500,"批量数据失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}

	//查询全部测量数据
	@RequestMapping("select")
	public JsonResult select(Integer pages,Integer line) {
		Bo bo = measureService.select(pages,line);
		if(bo.isBool()) {
			return new JsonResult(200,"查询数据成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询数据失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//查询全部测量数据数量
	@RequestMapping("selectSize")
	public JsonResult selectSize() {
		Bo bo = measureService.selectSize();
		if(bo.isBool()) {
			return new JsonResult(200,"查询数量成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询数量失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//查询业务数据(根据id)
	@RequestMapping("selectById")
	public JsonResult selectById(Integer id) {
		Bo bo = measureService.selectById(id);
		if(bo.isBool()) {
			return new JsonResult(200,"查询数据成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询数据失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//查询测量数据(根据机号/分页)
	@RequestMapping("selectByDeviceNum")
	public JsonResult selectByDeviceNum(String deviceNum,Integer pages,Integer line) {
		Bo bo = measureService.selectByDeviceNum(deviceNum,pages,line);
		if(bo.isBool()) {
			return new JsonResult(200,"查询数据成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询数据失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}

	//查询测量数据数量(根据机号/分页)
	@RequestMapping("selectByDeviceNumSize")
	public JsonResult selectByDeviceNumSize(String deviceNum) {
		Bo bo = measureService.selectByDeviceNumSize(deviceNum);
		if(bo.isBool()) {
			return new JsonResult(200,"查询数量成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询数量失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//查询测量数据(根据机型/分页)
	@RequestMapping("selectByTypeId")
	public JsonResult selectByTypeId(Integer TypeId,Integer pages,Integer line) {
		Bo bo = measureService.selectByTypeId(TypeId,pages,line);
		if(bo.isBool()) {
			return new JsonResult(200,"查询数据成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询数据失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//查询测量数据总数量(根据机型/分页)
	@RequestMapping("selectByTypeIdSize")
	public JsonResult selectByTypeIdSize(Integer TypeId) {
		Bo bo = measureService.selectByTypeIdSize(TypeId);
		if(bo.isBool()) {
			return new JsonResult(200,"查询数量成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询数量失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//查询测量数据(根据时间/分页)
	@RequestMapping("selectByTDate")
	public JsonResult selectByTDate(Long date1,Long date2,Integer pages,Integer line) {
		Bo bo = measureService.selectByTDate(date1,date2,pages,line);
		if(bo.isBool()) {
			return new JsonResult(200,"查询数据成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询数据失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}
	//查询测量数据总数量(根据时间/分页)
	@RequestMapping("selectByTDateSize")
	public JsonResult selectByTDateSize(Long date1,Long date2) {
		Bo bo = measureService.selectByTDateSize(date1,date2);
		if(bo.isBool()) {
			return new JsonResult(200,"查询数量成功",bo.getSize(),bo.getObject());
		}else {
			return new JsonResult(500,"查询数量失败: "+bo.getMessage(),bo.getSize(),null);
		}
	}

}
